{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ff68fc63",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd  # pyright: ignore[reportUnusedImport]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9f47b84a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "4    5\n",
       "dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pandas 基础数据类型\n",
    "# series \n",
    "list1 = [1,2,3,4,5]\n",
    "pd.Series(list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "3446262a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'a':1,'b':2,'c':3}\n",
    "s1 =pd.Series(dict1)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "497f27db",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['a', 'b', 'c'], dtype='object')"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2a736f35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a43b5dec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0  1  2\n",
       "0  1  2  3\n",
       "1  4  5  6\n",
       "2  7  8  9"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe\n",
    "# dataframe是一个二维的表格数据结构，每列可以是不同的数据类型\n",
    "# 可以从列表、字典、series等数据结构创建dataframe\n",
    "# 从列表创建dataframe\n",
    "list2 = [[1,2,3],[4,5,6],[7,8,9]]\n",
    "df1 = pd.DataFrame(list2)\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "fc1e1b76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\\nworld\\ttab\n"
     ]
    }
   ],
   "source": [
    "#字符转义\n",
    "#当字符串中包含特殊字符时，需要使用转义字符来表示\n",
    "#例如，下面的字符串中包含换行符和制表符\n",
    "s =R'hello\\nworld\\ttab'\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0ca4dd70",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>福利措施</th>\n",
       "      <th>同侪关系</th>\n",
       "      <th>适应学习</th>\n",
       "      <th>创新学习</th>\n",
       "      <th>知识获取</th>\n",
       "      <th>知识流通</th>\n",
       "      <th>知识创新</th>\n",
       "      <th>财务控管</th>\n",
       "      <th>顾客认同</th>\n",
       "      <th>内部运作</th>\n",
       "      <th>学习成长</th>\n",
       "      <th>组织效能</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>10</td>\n",
       "      <td>17</td>\n",
       "      <td>13</td>\n",
       "      <td>15</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>20</td>\n",
       "      <td>16</td>\n",
       "      <td>13</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>14</td>\n",
       "      <td>14</td>\n",
       "      <td>9</td>\n",
       "      <td>19</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>12</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12</td>\n",
       "      <td>13</td>\n",
       "      <td>7</td>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   福利措施  同侪关系  适应学习  创新学习  知识获取  知识流通  知识创新  财务控管  顾客认同  内部运作  学习成长  组织效能\n",
       "0     7     8     7     5     9     8     6     5     5     5     5    20\n",
       "1    11    10    17    13    15     7     4     5     5     5     5    20\n",
       "2     9    10     7     8    20    16    13     6    10     6     5    27\n",
       "3    12    14    14     9    19    14     4     5    12     7     5    29\n",
       "4    12    13     7    13    22    18    14     5     5    10     9    29"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用pandas读取数据文件\n",
    "#读取excel文件\n",
    "import pandas as pd\n",
    "df = pd.read_excel(R'D:\\P24101211 罗晨露 python\\luo-chenlu\\data\\xls\\多元回归分析演示数据.xlsx')\n",
    "df.head(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "c0cfa0a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country Name</th>\n",
       "      <th>longitude</th>\n",
       "      <th>latitude</th>\n",
       "      <th>1960</th>\n",
       "      <th>1961</th>\n",
       "      <th>1962</th>\n",
       "      <th>1963</th>\n",
       "      <th>1964</th>\n",
       "      <th>1965</th>\n",
       "      <th>1966</th>\n",
       "      <th>...</th>\n",
       "      <th>2009</th>\n",
       "      <th>2010</th>\n",
       "      <th>2011</th>\n",
       "      <th>2012</th>\n",
       "      <th>2013</th>\n",
       "      <th>2014</th>\n",
       "      <th>2015</th>\n",
       "      <th>2016</th>\n",
       "      <th>2017</th>\n",
       "      <th>2018</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>-0.07858</td>\n",
       "      <td>51.50476</td>\n",
       "      <td>7.232805e+10</td>\n",
       "      <td>7.669436e+10</td>\n",
       "      <td>8.060194e+10</td>\n",
       "      <td>8.544377e+10</td>\n",
       "      <td>9.338760e+10</td>\n",
       "      <td>1.010000e+11</td>\n",
       "      <td>1.070000e+11</td>\n",
       "      <td>...</td>\n",
       "      <td>2390000000000</td>\n",
       "      <td>2450000000000</td>\n",
       "      <td>2630000000000</td>\n",
       "      <td>2680000000000</td>\n",
       "      <td>2750000000000</td>\n",
       "      <td>3030000000000</td>\n",
       "      <td>2900000000000</td>\n",
       "      <td>2660000000000</td>\n",
       "      <td>2640000000000</td>\n",
       "      <td>2830000000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>United States</td>\n",
       "      <td>-77.04026</td>\n",
       "      <td>38.85169</td>\n",
       "      <td>5.430000e+11</td>\n",
       "      <td>5.630000e+11</td>\n",
       "      <td>6.050000e+11</td>\n",
       "      <td>6.390000e+11</td>\n",
       "      <td>6.860000e+11</td>\n",
       "      <td>7.440000e+11</td>\n",
       "      <td>8.150000e+11</td>\n",
       "      <td>...</td>\n",
       "      <td>14400000000000</td>\n",
       "      <td>15000000000000</td>\n",
       "      <td>15500000000000</td>\n",
       "      <td>16200000000000</td>\n",
       "      <td>16800000000000</td>\n",
       "      <td>17500000000000</td>\n",
       "      <td>18200000000000</td>\n",
       "      <td>18700000000000</td>\n",
       "      <td>19500000000000</td>\n",
       "      <td>20500000000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Russian Federation</td>\n",
       "      <td>37.59411</td>\n",
       "      <td>55.75306</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>1220000000000</td>\n",
       "      <td>1520000000000</td>\n",
       "      <td>2050000000000</td>\n",
       "      <td>2210000000000</td>\n",
       "      <td>2300000000000</td>\n",
       "      <td>2060000000000</td>\n",
       "      <td>1360000000000</td>\n",
       "      <td>1280000000000</td>\n",
       "      <td>1580000000000</td>\n",
       "      <td>1660000000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>France</td>\n",
       "      <td>2.29363</td>\n",
       "      <td>48.87372</td>\n",
       "      <td>6.265147e+10</td>\n",
       "      <td>6.834674e+10</td>\n",
       "      <td>7.631378e+10</td>\n",
       "      <td>8.555111e+10</td>\n",
       "      <td>9.490659e+10</td>\n",
       "      <td>1.020000e+11</td>\n",
       "      <td>1.110000e+11</td>\n",
       "      <td>...</td>\n",
       "      <td>2690000000000</td>\n",
       "      <td>2640000000000</td>\n",
       "      <td>2860000000000</td>\n",
       "      <td>2680000000000</td>\n",
       "      <td>2810000000000</td>\n",
       "      <td>2850000000000</td>\n",
       "      <td>2440000000000</td>\n",
       "      <td>2470000000000</td>\n",
       "      <td>2590000000000</td>\n",
       "      <td>2780000000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>China</td>\n",
       "      <td>116.39213</td>\n",
       "      <td>39.90071</td>\n",
       "      <td>5.971647e+10</td>\n",
       "      <td>5.005687e+10</td>\n",
       "      <td>4.720936e+10</td>\n",
       "      <td>5.070680e+10</td>\n",
       "      <td>5.970834e+10</td>\n",
       "      <td>7.043627e+10</td>\n",
       "      <td>7.672029e+10</td>\n",
       "      <td>...</td>\n",
       "      <td>5100000000000</td>\n",
       "      <td>6090000000000</td>\n",
       "      <td>7550000000000</td>\n",
       "      <td>8530000000000</td>\n",
       "      <td>9570000000000</td>\n",
       "      <td>10400000000000</td>\n",
       "      <td>11000000000000</td>\n",
       "      <td>11100000000000</td>\n",
       "      <td>12100000000000</td>\n",
       "      <td>13600000000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 62 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Country Name  longitude  latitude          1960          1961  \\\n",
       "0      United Kingdom   -0.07858  51.50476  7.232805e+10  7.669436e+10   \n",
       "1       United States  -77.04026  38.85169  5.430000e+11  5.630000e+11   \n",
       "2  Russian Federation   37.59411  55.75306           NaN           NaN   \n",
       "3              France    2.29363  48.87372  6.265147e+10  6.834674e+10   \n",
       "4               China  116.39213  39.90071  5.971647e+10  5.005687e+10   \n",
       "\n",
       "           1962          1963          1964          1965          1966  ...  \\\n",
       "0  8.060194e+10  8.544377e+10  9.338760e+10  1.010000e+11  1.070000e+11  ...   \n",
       "1  6.050000e+11  6.390000e+11  6.860000e+11  7.440000e+11  8.150000e+11  ...   \n",
       "2           NaN           NaN           NaN           NaN           NaN  ...   \n",
       "3  7.631378e+10  8.555111e+10  9.490659e+10  1.020000e+11  1.110000e+11  ...   \n",
       "4  4.720936e+10  5.070680e+10  5.970834e+10  7.043627e+10  7.672029e+10  ...   \n",
       "\n",
       "             2009            2010            2011            2012  \\\n",
       "0   2390000000000   2450000000000   2630000000000   2680000000000   \n",
       "1  14400000000000  15000000000000  15500000000000  16200000000000   \n",
       "2   1220000000000   1520000000000   2050000000000   2210000000000   \n",
       "3   2690000000000   2640000000000   2860000000000   2680000000000   \n",
       "4   5100000000000   6090000000000   7550000000000   8530000000000   \n",
       "\n",
       "             2013            2014            2015            2016  \\\n",
       "0   2750000000000   3030000000000   2900000000000   2660000000000   \n",
       "1  16800000000000  17500000000000  18200000000000  18700000000000   \n",
       "2   2300000000000   2060000000000   1360000000000   1280000000000   \n",
       "3   2810000000000   2850000000000   2440000000000   2470000000000   \n",
       "4   9570000000000  10400000000000  11000000000000  11100000000000   \n",
       "\n",
       "             2017            2018  \n",
       "0   2640000000000   2830000000000  \n",
       "1  19500000000000  20500000000000  \n",
       "2   1580000000000   1660000000000  \n",
       "3   2590000000000   2780000000000  \n",
       "4  12100000000000  13600000000000  \n",
       "\n",
       "[5 rows x 62 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取csv文件\n",
    "import pandas as pd\n",
    "df = pd.read_csv(R'D:\\P24101211 罗晨露 python\\luo-chenlu\\data\\csv\\GDP.csv')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d9264ea9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>宝鸡文理学院</td>\n",
       "      <td>基于机械视觉的分类和处理垃圾桶的设计</td>\n",
       "      <td>物联网应用</td>\n",
       "      <td>王俊豪 王旭 罗益</td>\n",
       "      <td>周新淳 钱郁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>宝鸡文理学院</td>\n",
       "      <td>e家居--基于物联网的智能房车控制系统</td>\n",
       "      <td>物联网应用</td>\n",
       "      <td>刘楠 孙龙桥 冯新洋</td>\n",
       "      <td>张磊</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        0                    1      2           3       4\n",
       "0  宝鸡文理学院   基于机械视觉的分类和处理垃圾桶的设计  物联网应用   王俊豪 王旭 罗益  周新淳 钱郁\n",
       "1  宝鸡文理学院  e家居--基于物联网的智能房车控制系统  物联网应用  刘楠 孙龙桥 冯新洋      张磊"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取pdf格式中的表格\n",
    "import pdfplumber\n",
    "\n",
    "pdf = pdfplumber.open(R'D:\\P24101211 罗晨露 python\\luo-chenlu\\data\\pdf\\2022西北地区赛国赛推选名单.pdf')\n",
    "\n",
    "table = []\n",
    "#len(pdf.pages)获取全部pdf页数\n",
    "for i in range(len(pdf.pages)-1):\n",
    "    #通过循环逐页读取当前页面中的表格\n",
    "    page = pdf.pages[i + 1]\n",
    "    table.extend(page.extract_table())\n",
    "    #将表格转换为Pandas中的DataFrame\n",
    "table_df = pd.DataFrame(table[2:])\n",
    "table_df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "c4f78666",
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用pandas将DataFrame保存为csv文件\n",
    "table_df.to_csv(R'output/dict.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
